package com.course.controller;

import com.course.convert.StrToListFormatter;
import com.course.entity.dto.CourseDto;
import com.course.entity.dto.SmallCourseTypeDto;
import com.course.entity.vo.SmallCourseTypeVo;
import com.course.service.ISmallCourseTypeService;
import com.easyCode.feature.mybaits.CustomPage;
import com.easyCode.feature.result.ResponseResultAdvice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.DataBinder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Positive;
import java.util.List;

@Validated
@RestController
@RequestMapping("/smallCourseType")
@RequiredArgsConstructor
@ResponseResultAdvice
@Api(tags = "课程小类请求")
public class SmallCourseTypeController {
    private final ISmallCourseTypeService iSmallCourseTypeService;

    @ApiOperation("新增课程小类")
    @PostMapping("/save")
    public Integer saveSmallCourseType(@Validated SmallCourseTypeVo smallcoursetypeVo) {
        return iSmallCourseTypeService.saveSmallCourseType(smallcoursetypeVo);
    }

    @ApiOperation("根据id查询课程小类")
    @GetMapping("/{id}")
    public SmallCourseTypeDto getSmallCourseType(@Positive(message = "id不合法")@PathVariable("id") Integer id) {
        return iSmallCourseTypeService.getSmallCourseTypeById(id);
    }

    @ApiOperation("分页批量查询课程小类")
    @GetMapping("/list")
    public List<SmallCourseTypeDto> listSmallCourseType(CustomPage customPage) {
        return iSmallCourseTypeService.listSmallCourseType(customPage);
    }

    @ApiOperation("列举课程小类下的课程列表")
    @GetMapping("/courses/{id}")
    public List<CourseDto> listCourseOfSmallCourseType(@Positive(message = "id不合法")@PathVariable("id") Integer id, CustomPage customPage){
         return iSmallCourseTypeService.listCourseOfSmallCourseType(id,customPage);
    }

    @ApiOperation("删除课程小类")
    @DeleteMapping("/{id}")
    public void delSmallCourseType(@Positive(message = "id不合法")@PathVariable("id") Integer id) {
        iSmallCourseTypeService.delSmallCourseTypeById(id);
    }
}
